<template>
	<view>
		<uni-nav-bar title="我的诊断" backgroundColor="#fff" color="#000" @clickLeft="back()" left-icon="arrowleft"
			statusBar="true">
		</uni-nav-bar>
		<view class="main">
			<view class="content">
				<scroll-view class="scrollView" scroll-y="true" @scrolltolower="scrollView()"
					:style="{height: setcollapseheight() + 'px'}">
					<view style="padding-bottom: 20rpx;">
						<view v-if="myDiagnosticList.length>0">
							<view class="contentItem" v-for="(it,index) in myDiagnosticList" :key="index"
								@click="goInfo(it)">
								<view class="header">
									<view class="serialnumber"></view>
									<view class="title">
										{{it.invitationTitle}}
										
									</view>
									<view class="right">
										<view class="img1" v-if="it.topFlag">
											<view class="line"></view>
											置顶
											<view class="san">
											</view>
										</view>
										<view class="img2" v-if="it.choicenessFlag">
											<view class="line"></view>
											精
										</view>
										<view class="newReply" v-if="!it.exchangeNewIsSelf">
											<template style="position: relative;">
												<view class="txt">
													新回复
												</view>
											</template>

										</view>
									</view>
								</view>
								<view class="container">
									<view class="img">
										<image src="@/static/index-message/V.png"></image>
									</view>
									<view class="text">
										{{it.invitationContent}}
									</view>
								</view>
								<view class="container">
									<view class="img3">
										<image src="@/static/index-message/jingliren.png"></image>
									</view>
									<view class="text" v-if="it.publisher">
										问帖人：{{it.publisher.nickName}}
									</view>
									<view class="text" v-else>
										问帖人：{{undefined}}
									</view>
								</view>
								<view class="container">
									<view class="img4">
										<image src="@/static/index-message/unit.png"></image>
									</view>
									<view class="text">
										问帖时间：{{it.createTime}}
									</view>
								</view>
								<view class="container">
									<view class="img4">
										<image src="@/static/index-message/liulanliang.png"></image>
									</view>
									<view class="text">
										浏览量：{{it.pageView}}
									</view>
								</view>
							</view>
						</view>
						<view v-if="myDiagnosticList.length==0">
							<view class="blank">
								<image src="@/static/blank.png" mode=""></image>
								<view class="nodata">
									暂无数据
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		
		<bottomTabar></bottomTabar>
	</view>
</template>

<script>
	import bottomTabar from '../../components/bottom-tabar/index.vue'
	import navBar from '../../components/nav-bar/index.vue'
	import search from '../../components/search/index.vue'
	import containerItem from '../../components/container-item/index.vue'
	import Api from '@/api/socialized-servce/specialist-consultation/expert-module/my-diagnosis/index.js'
	export default {
		components: {
			bottomTabar,
			navBar,
			search,
			containerItem
		},
		data() {
			return {
				myDiagnosticList: [],
				invitationId: '',
				page: 1,
				size: 10,
				total: 0,
				type: ''
			}
		},
		mounted() {
			this.setcollapseheight()
		},
		onLoad(e) {
			this.type = e.type
		},
		created() {
			this.getMyDiagnosticList()
		},
		methods: {
			async getMyDiagnosticList() {
				let params = {
					page: this.page,
					size: this.size,
					condition: {
						serviceProviderNo: uni.getStorageSync('serviceProviderNo')
					}
				}
				let res = await Api.queryExpertAllPostList(params)
				if (res.code == 200) {
					let arr = res.data.content
					this.total = res.data.totalElements
					this.myDiagnosticList = [...this.myDiagnosticList, ...arr]
					this.myDiagnosticList.sort((a, b) => {
					   if (a.topFlag && !b.topFlag) {
					     return -1;
					   } else if (!a.topFlag && b.topFlag) {
					     return 1;
					   } else {
					     return 0;
					   }
					 })
				}
			},
			setcollapseheight() {
				let topheightone = uni.upx2px(136)
				let winHeight = 0
				uni.getSystemInfo({
					success: function(res) {
						winHeight = res.windowHeight
					}
				});
				let oldHeight = uni.upx2px(168)

				winHeight = parseInt(winHeight) - topheightone - oldHeight
				// #ifndef H5
				winHeight = winHeight

				// #endif
				return winHeight
			},
			shareSearchList(e, x) {
				this.myDiagnosticList = e
				this.page = x
			},
			scrollView() {
				if (this.total > this.myDiagnosticList.length) {
					this.page++
					this.getMyDiagnosticList()
				} else {
					console.log('触底');
					return
				}
			},
			onPullDownRefresh() {
				console.log('下拉');
				this.page = 1
				this.myDiagnosticList = []
				this.getMyDiagnosticList()
				setTimeout(function() {
					uni.stopPullDownRefresh()
				}, 1000)
			},
			goInfo(it) {
				uni.navigateTo({
					url: `/subPage1/socialized-service/specialist-consultation/expert-module/my-diagnosis/diagnosis-details/diagnosis-details?id=${it.invitationId}`
				})
			},
			back() {
				if(this.type) {
					uni.switchTab({
						url: '/pages/socialized-service/person-message/person-message'
					})
				} else {
					uni.reLaunch({
						url: '/pages/socialized-service/selection-system/selection-system'
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		width: 100%;
		margin-top: 20rpx;
		background: #F5F6FA;

		.content {
			position: relative;
			padding: 0 40rpx;
			background: #F5F6FA;

			.blank {
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translateX(-50%) translateY(-50%);
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				margin: 0 32rpx;
				margin-top: 16rpx;

				image {
					width: 200rpx;
					height: 200rpx;
				}

				.nodata {
					margin-top: 20rpx;
				}
			}
			
			.contentItem {
				position: relative;
				margin-top: 16rpx;
				background-color: #FFFFFF;
				padding: 36rpx 12rpx 40rpx 12rpx;
				box-shadow: 0rpx 0rpx 12rpx 2rpx rgba(0, 0, 0, 0.05);
				border-radius: 16rpx 16rpx 16rpx 16rpx;

				.header {
					display: flex;
					justify-content: space-between;
					position: relative;

					.serialnumber {
						position: absolute;
						top: 8rpx;
						left: 0;
						width: 10rpx;
						height: 28rpx;
						background-color: #91743E;
					}

					.title {
						padding-left: 24rpx;
						font-size: 32rpx;
						width: 50%;
						font-weight: 500;
						color: #91743E;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.right {
						display: flex;
						.img1,
						.img2 {
							position: relative;
							top: -26rpx;
							width: 60rpx;
							height: 60rpx;
							text-align: center;
							color: #fff;
							background-color: #fa9f03;

							.line {
								position: absolute;
								top: -10rpx;
								width: 60rpx;
								height: 4rpx;
								background-color: red;
								border-radius: 6rpx;
								background-color: #fa9f03;
							}

							.san {
								position: absolute;
								top: 5rpx;
								border: 30rpx solid red;
								border-color: transparent transparent #fff transparent;
							}
						}

						.img2 {
							margin-left: 20rpx;
							background-color: #ff7072;
							border-radius: 0 0 10rpx 10rpx;

							.line {
								background-color: #ff7072;
							}
						}

						.newReply {
							position: relative;
							top: -30rpx;
							right: -20rpx;
							width: 148rpx;
							height: 152rpx;
							background: url('@/static/index-message/replay.png') no-repeat 100% 100%;

							.txt {
								position: absolute;
								transform: rotate(45deg);
								right: 32rpx;
								top: 30rpx;
								color: #fff;
							}
						}
					}
				}

				.container {
					display: flex;
					align-items: center;
					margin-left: 32rpx;
					margin-right: 10rpx;
					margin-top: 30rpx;
					font-size: 28rpx;
					font-family: Source Han Sans CN-Regular, Source Han Sans CN;
					font-weight: 400;
					color: #272727;

					.img {
						width: 35rpx;
						height: 30rpx;

						image {
							position: relative;
							z-index: 999;
							width: 35rpx;
							height: 30rpx;
						}
					}

					.img3 {
						width: 30rpx;
						height: 30rpx;

						image {
							position: relative;
							z-index: 999;
							width: 27rpx;
							height: 35rpx;
						}
					}

					.img4 {
						width: 35rpx;
						height: 26rpx;

						image {
							position: relative;
							z-index: 999;
							width: 35rpx;
							height: 26rpx;
						}
					}

					.text {
						padding-left: 24rpx;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
						overflow: hidden;
					}
				}

				.solution,
				.unsolution {
					position: absolute;
					width: 220rpx;
					height: 48rpx;
					right: 0;
					bottom: 0;
					font-size: 28rpx;
					font-family: Arial-Bold, Arial;
					font-weight: 400;
					color: #fff;
					text-align: center;
					line-height: 48rpx;
					background: linear-gradient(135deg, #00B2B2 0%, #00B790 100%);
					border-radius: 10rpx 0rpx 10rpx 0rpx;
				}

				.unsolution {
					background: linear-gradient(135deg, #FF6E6E 0%, #F73737 100%);
				}
			}
		}
	}
</style>